package g.m.springcloud.controller;

import g.m.springcloud.entities.User;
import g.m.springcloud.service.CreateService;
import g.m.springcloud.service.DeleteService;
import g.m.springcloud.service.ReadService;
import g.m.springcloud.service.UpdateService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {

    @Resource
    private CreateService createService;

    @Resource
    private UpdateService updateService;

    @Resource
    private DeleteService deleteService;

    @Resource
    private ReadService readService;

    @PostMapping(value = "/consumer/create")
    public void create(@RequestBody User user){


        createService.create(user);
    }

    @PostMapping(value = "/consumer/update")
    void update(@RequestBody User user){
        updateService.update(user);
    }

    @GetMapping(value = "/consumer/delete/{id}")
    void delete(@PathVariable("id") Integer id){
        deleteService.delete(id);
    }

    @GetMapping(value = "/consumer/read")
    List<User> read(){
        return readService.read();
    }
}
